/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __MULTIFILE_RESOURCE_H__
#define __MULTIFILE_RESOURCE_H__

#include "Resource.h"
#include <filesystem/String.hpp>
#include <filesystem/File.h>
#include <filesystem/Finder.h>
#include <AutoContainer.h>
#include <NoCopy.h>
#include <threads/Lock.h>
#include <vector>
#include <list>
#include <map>

#ifdef WIN_VERSION
#include <win32/win32.h>
#include "rar3.5.1/rar.hpp"
#else
struct Archive
{};
#endif

namespace liba
{
namespace resource
{

class MultiFile
{
	struct ArchiveData
	{
		__int64 pos;
		Archive * arc;
	};

	AutoContainer< std::vector<Archive *> > archives;

	typedef std::map<filesystem::String, ArchiveData> ImplMap;
	ImplMap impls;
	typedef std::map<filesystem::String, std::vector<char> > LoadedImplMap;
	LoadedImplMap loaded_impls;

	typedef std::list<filesystem::String> FolderList;
	FolderList folder_list;

	std::string password;
	threads::Mutex mutex;
public:
	MultiFile(const std::string & password);
	~MultiFile();

	bool find(filesystem::Finder * finder, const filesystem::String & base_path);

	void add_multifile(const filesystem::String & name);
	Resource * create_resource(const filesystem::String & name);

	bool ExtractCurrentFile(Archive &Arc,int HeaderSize,bool &Repeat);
};

} // namespace resource
} // namespace liba

using namespace liba;

#endif //__MULTIFILE_RESOURCE_H__

